#ifndef DB_RAW_ACCESS_H
#define DB_RAW_ACCESS_H

#include <stdint.h>
#include <stddef.h>

/************maxDBSizeStart*************/
// NOTE 负压暂定为2K，其他程序需要注意一下
#define S7_BUFFER_SIZE 2048
/************maxDBSizeEnd***************/

typedef struct {
  void*  pointer;
  size_t size;
  void (*PackDBCall)(uint8_t* buffer, size_t buffer_size);
  void (*UnPackDBCall)(uint8_t* buffer, size_t buffer_size);
} DBPointer;

DBPointer FindDBPointerByNumber(uint16_t dbNumber);

extern uint8_t s7_buffer[S7_BUFFER_SIZE];

// 写入通讯数组函数
void write_bool_be(uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint8_t* value);
void read_bool_be(const uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint8_t* value);
void write_u8_be(uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint8_t* value);
void read_u8_be(const uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint8_t* value);
void write_u16_be(uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint16_t* value);
void read_u16_be(const uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint16_t* value);
void write_u32_be(uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint32_t* value);
void read_u32_be(const uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint32_t* value);
void write_u64_be(uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint64_t* value);
void read_u64_be(const uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, uint64_t* value);
void write_char_array_be(
    uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, char* str, size_t str_len);
void read_char_array_be(
    const uint8_t* buffer, size_t buf_size, uint16_t byteOffset, uint8_t bitOffset, char* str, size_t str_len);

#endif // DB_RAW_ACCESS_H
